package exam.business.service;

import java.util.Date;

import exam.common.constant.ResultPort;
import exam.common.key.KeyUser;
import exam.common.util.MD5;
import exam.common.util.NullCheckUtil;
import exam.model.dao.TUserDAO;
import exam.model.entity.TUserEntity;
import exam.system.business.AbstractService;
import exam.system.business.BusinessServiceInfo;
/**
 * <p>
 * UserAddService
 * </p>
 * <p>
 * Xử lý yêu cầu thêm người dùng
 * </p>
 * 
 * @author Phong
 * @version 19/5/2012
 */
public class UserAddService extends AbstractService {
	private TUserDAO tUserDAO = new TUserDAO();
	@Override
	public String executeService(BusinessServiceInfo serviceInfo)
			throws Exception {
		// TODO Auto-generated method stub
		TUserEntity tUserEntity = serviceInfo.getObject(KeyUser.T_USER_ENTITY);
		if(NullCheckUtil.isNotNull(tUserEntity)) {
			tUserEntity.setPassword(MD5.encryption(tUserEntity.getPassword()));
			tUserEntity.setCreateDate(new Date());
			tUserEntity.setUpdateDate(new Date());
			int rs = tUserDAO.insertUser(tUserEntity);
			if(rs != 0) {
				return ResultPort.SUCCESS;
			} else {
				return ResultPort.FAIL;
			}
		}
		return ResultPort.ERROR;
	}
}
